package com.fengdao.demo.controller;

import com.fengdao.demo.model.UserEntity;
import com.fengdao.demo.pojo.UserReq;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Administrator
 */

@Tag(name = "测试接口", description = "测试接口")
//@Tag(name = "测试接口", description = "测试接口", extensions = {
//        @Extension(properties = {@ExtensionProperty(name = "x-order", value = "200", parseValue = true)}
//        )
//})
@ApiSupport(order = 200)
@RestController
@RequestMapping("/test")
public class TestController {


    @ApiOperationSupport(order = 1)
    @Operation(summary = "01-问好")
    @GetMapping("/hello")
    public String hello() {
        return "hello";
    }


    @ApiOperationSupport(order = 2)
    @Operation(summary = "02-测试实体")
    @PostMapping("/tetstEntity")
    public UserEntity tetstEntity(@RequestBody UserReq req) {
        UserEntity entity = new UserEntity(req.getId(), req.getNickname(), req.getUsername(), req.getPassword());
        return entity;
    }

    @ApiOperationSupport(order = 3)
    @Operation(summary = "03-普通body请求+Param+Header+Path")
    @Parameters({
            @Parameter(name = "id", description = "id", in = ParameterIn.PATH),
            @Parameter(name = "token", description = "请求token", required = true, in = ParameterIn.HEADER),
            @Parameter(name = "name", description = "名称", required = true, in = ParameterIn.QUERY)
    })
    @PostMapping("/bodyParamHeaderPath/{id}")
    public ResponseEntity<UserEntity> bodyParamHeaderPath(@PathVariable("id") String id, @RequestHeader("token") String token, @RequestParam("name") String name, @RequestBody UserReq req) {

        UserEntity entity = new UserEntity(req.getId(), req.getNickname(), req.getUsername(), req.getPassword());
        return ResponseEntity.ok(entity);
    }


    @ApiOperationSupport(order = 4)
    @Operation(summary = "04-删除用户接口" )
    @Parameter(name = "id", description = "用户id", in = ParameterIn.PATH)
    @DeleteMapping("/delete/{id}")
    public void deleteUserById(@PathVariable("id") Long id) {
        //   业务逻辑
    }
}